#!/usr/bin/env bash

# cd 到上级目录, 进行统计
curr_dir=`dirname $0`
cd $curr_dir
cd ..

# git 提交统计
git log | awk '/Author/ {print $2}' | sort | uniq -c | sort -r

# java 文件统计
java_file_no=`find . -name "*.java" | wc -l`
java_file_no="$(echo -e "${java_file_no}" | sed -e 's/^[[:space:]]*//')"    # remove leading space
printf "%-16s %s\n" "java_file_no"  "$java_file_no"

java_max_line=`find . -name "*.java" -exec wc -l {} \; | sort -nr | head -1`
java_max_line="$(echo -e "${java_max_line}" | sed -e 's/^[[:space:]]*//')"
printf "%-16s %s\n" "java_max_line"  "$java_max_line"

java_total_line=`paste -s -d+ <(find . -name "*.java" -exec wc -l {} \; | awk '{print $1}') | bc `
java_total_line="$(echo -e "${java_total_line}" | sed -e 's/^[[:space:]]*//')"
printf "%-16s %s\n" "java_total_line"  "$java_total_line"

# xml 文件统计
xml_file_no=`find . -name "*Mapper.xml" | wc -l`
xml_file_no="$(echo -e "${xml_file_no}" | sed -e 's/^[[:space:]]*//')"
printf "%-16s %s\n" "xml_file_no"  "$xml_file_no"

xml_max_line=`find . -name "*Mapper.xml" -exec wc -l {} \; | sort -nr | head -1`
xml_max_line="$(echo -e "${xml_max_line}" | sed -e 's/^[[:space:]]*//')"
printf "%-16s %s\n" "xml_max_line"  "$xml_max_line"

xml_total_line=`paste -s -d+ <(find . -name "*Mapper.xml" -exec wc -l {} \; | awk '{print $1}') | bc `
xml_total_line="$(echo -e "${xml_total_line}" | sed -e 's/^[[:space:]]*//')"
printf "%-16s %s\n" "xml_total_line"  "$xml_total_line"
